package com.java.program_questions;

import java.util.Scanner;

/**
 * 问题：求一个3*3矩阵对角线元素之和
 * 分析：利用双重for循环控制输入二维数组，再将a[i][i]累加后输出
 */
public class Question29 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入一个3*3矩阵");

        int[][] a = new int[3][3];
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                a[i][j] = sc.nextInt();
            }
        }
        int b = a[0][0] + a[1][1] + a[2][2];
        System.out.print("对角线元素之和：" + b);
    }
}
